import { User, UserProfile } from '@/types/data'
import { UserAction } from '@/types/store'

type proRespone = {
  user: User
  userProfile: UserProfile
}

const initalState = {
  user: {},
  userProfile: {},
} as proRespone
const profile = (state = initalState, action: UserAction): proRespone => {
  switch (action.type) {
    // 获取个人资料
    case 'User/get':
      return {
        ...state,
        user: action.payload,
      }

    // 获取个人页面信息
    case 'profile/getUserProfile':
      return {
        ...state,
        userProfile: action.payload,
      }

    // 更新昵称、简介等
    case 'Profile/Updata':
      return {
        ...state,
        userProfile: {
          ...state.userProfile,
          // 注意：这是要修改的数据，一定要放在 state.userProfile 的后面，才能覆盖原始数据
          ...action.payload,
        },
      }
    default:
      return state
  }
}

export default profile
